<?php
namespace Website\Controller;

use \Service\Library\LibConfig;
use \Service\Library\LibTemplate;

/**
 * Base Controller
 * All controllers must extends this controller
 */
abstract class BaseController
{
    /**
     * Panda frameworks instance
     * @param object 
     */
    public $panda;

    /**
     * Timestamp (Length 10)
     * @param integer
     */
    public $time;

    /**
     * Day (Y-m-d H:i:s)
     * 
     */
    public $day;

    public $view;

    public function __construct(& $panda)
    {
        $this->panda = $panda;

        // init vars
        $this->time = time();
        $this->day = date('Y-m-d H:i:s');

        $this->loadView();
    }

    public function loadView()
    {
        $tpl_path = $this->panda->app_path . LibConfig::get('local')['tpl_path'];
        $this->view = new LibTemplate($tpl_path);
    }

    public function renderJson(array $data)
    {
        header('Content-Type: application/json; charset=utf-8');
        echo json_encode($data, JSON_UNESCAPED_UNICODE);
    }
}